#!/bin/bash
paramCount=$#
paramAll=$@
param1=$1

# 参数个数校验
if [ $paramCount -eq 0 ];then
   echo "参数输入错误"
   exit 1
fi

# 遍历所有应用
for app in ${paramAll};  do
	echo "正在处理入参=${app}"
	jarPath=
	case $app in
		share-user-web | user-web | user)
		 jarPath="share-user-web/target/share-user-web.jar"
		;;

		
		share-alibaba-agetway | alibaba-agetway | agetway)
		 jarPath="share-alibaba/share-alibaba-agetway/target/share-alibaba-agetway.jar"
		;;
		share-alibaba-auser-web | alibaba-auser-web | auser-web | auser)
		 jarPath="share-alibaba/share-alibaba-auser-web/target/share-alibaba-auser-web.jar"
		;;
		share-alibaba-editor-web | alibaba-editor-web | editor-web | editor)
		 jarPath="share-alibaba/share-alibaba-editor-web/target/share-alibaba-editor-web.jar"
		;;
		

		share-cloud-server-config | cloud-server-config)
		 jarPath="share-cloud/share-cloud-server/share-cloud-server-config/target/share-cloud-server-config.jar"
		;;
		share-cloud-server-eureka | cloud-server-eureka)
		 jarPath="share-cloud/share-cloud-server/share-cloud-server-eureka/target/share-cloud-server-eureka.jar"
		;;

				
		share-cloud-cgetway | cloud-cgetway | cgetway)
		 jarPath="share-cloud/share-cloud-cgetway/target/share-cloud-cgetway.jar"
		;;
		share-cloud-cuser-web | cloud-cuser-web | cuser-web | cuser)
		 jarPath="share-cloud/share-cloud-cuser-web/target/share-cloud-cuser-web.jar"
		;;
		share-cloud-news-web | cloud-news-web | news-web | news)
		 jarPath="share-cloud/share-cloud-news-web/target/share-cloud-news-web.jar"
		;;


		share-tool-devops-web | tool-devops-web | devops-web | devops)
		 jarPath="share-tool/share-tool-devops-web/target/share-tool-devops-web.jar"
		;;
		share-tool-mock-web | tool-mock-web | mock-web | mock)
		 jarPath="share-tool/share-tool-mock-web/target/share-tool-mock-web.jar"
		;;
	esac

	if [ ! -n "$jarPath" ]; then  
		echo "-------参数输入错误-------"
		exit 2  
	else
		appPid=`ps -ef | grep $jarPath | grep -v grep | awk '{print $2}'`
		if [ -n "$appPid" ]; then 
		    echo "正在杀死pid=${appPid}" 
			kill -9 $appPid
		fi
				
		nohup java -jar $jarPath > /dev/null 2>&1 &
		
		sleep 3
		appPid=`ps -ef | grep $jarPath | grep -v grep | awk '{print $2}'`
		if [ ! -n "$appPid" ]; then  
			echo -e "$jarPath 启动失败>>>>>>>\n"
			exit 3  
		else
			echo -e "$jarPath ------启动成功\n"
		fi
	fi 
done
exit 0
